package ui2;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;

import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.ImageIcon;

public class firstFrame {
	
	private JFrame frame;
	private JTextField configFileTextBox;
	private JFileChooser chooser = new JFileChooser(new File(""));
	File f = null;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					firstFrame window = new firstFrame();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public firstFrame() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		frame.getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JLabel lblConfigFile = new JLabel("Config File");
		lblConfigFile.setBounds(39, 54, 68, 16);
		panel.add(lblConfigFile);
		
		configFileTextBox = new JTextField();
		configFileTextBox.setBounds(119, 48, 217, 28);
		panel.add(configFileTextBox);
		configFileTextBox.setColumns(10);
		
		JButton browseButton = new JButton("Search");
		browseButton.setIcon(new ImageIcon(firstFrame.class.getResource("/resources/configDiscovery.png")));
		browseButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				chooser.setAcceptAllFileFilterUsed(false);
				int returnVal = chooser.showOpenDialog(chooser);
				if(returnVal == JFileChooser.APPROVE_OPTION) {
					f = chooser.getSelectedFile();
					configFileTextBox.setText(f.getPath());
				}	
			}
		});
		browseButton.setBounds(348, 49, 72, 29);
		panel.add(browseButton);
		
		JCheckBox discoveryModeCheckBox = new JCheckBox("Discovery mode");
		discoveryModeCheckBox.setBounds(160, 134, 147, 23);
		panel.add(discoveryModeCheckBox);
		
		JButton cancelButton = new JButton("CANCEL");
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);	
			}
		});
		cancelButton.setBounds(94, 218, 110, 29);
		panel.add(cancelButton);
		
		JButton okButton = new JButton("OK");
		okButton.setBounds(251, 218, 110, 29);
		panel.add(okButton);
	}
}
